<?php

/**
 * Class of Validate Turned Day template
 *
 * @author BUI TIEN HIEP
 * @email bthiep@lhv.vn
 */
class ValidateTurnedDay extends AbstractValidateFactory {
    public function __construct($policy) {
        $this->policy = $policy;
    }
    /**
     * Validate turned day
     * @param type $expenses
     * @return boolean
     */
    public function validate($expenses = array()) {
        $bRet = false;
        $field = $this->policy['rules'][0]['field']; 
        $value = $this->policy['rules'][0]['value'];
        $now = time(); // or your date as well
        foreach($expenses as $expense){
            $date = strtotime($expense[$field]);
            $dateDiff = floor(($now - $date)/(60*60*24));
            if($dateDiff > $value)
            {
                $bRet = true;
                $this->message = $this->policy['message'];
                break;
            }
        }
        return $bRet;
        
    }

}
